HAL DAC migration: List of applicable concepts

This section provides information about the HAL DAC applicable architecture concepts.

Concepts for DAC

Concept

Description

Separation of initialization and configuration functions

The Init has been split into two functions :

  • HAL_DAC_Init: Initializes the handle and link it to an DAC instance.

  • HAL_DAC_SetConfig: Configure the common DAC settings (The frequency interface mode).

Removal and conversion of init structure to configuration structure

The init structure has been removed and moved to the HAL_DAC_SetConfig function.

Renaming of the handle structure

The handle structure has been renamed to hal_dac_handle_t.

Remove MspInit and MspDeInit callbacks

HAL_DAC_MspInit and HAL_DAC_MspDeInit are no longer available and have been replaced by a user sequence to initialize and configure the DAC.

Unitary configuration APIs

New APIs are available to get and set DAC features.

Dedicated DMA link APIs replace generic __HAL_LINKDMA macro

Provide HAL_DAC_SetChannelDMA() and HAL_DAC_SetDualChannelDMA().

Introduction of HAL user data set/get APIs

Two functions to set and get user data are available: HAL_DAC_SetUserData() and HAL_DAC_GetUserData().

Individual callback registration APIs replace global register and unregister functions

The callback registration is handled by specific functions for each DAC event. These functions are used to register callback functions for different DAC events.

HAL implementation with LL inline functions

HAL DAC APIs now rely on LL APIs rather than performing direct register access.

Define statements and enumerations redirected to LL equivalents

HAL DAC define statements and enumerations are based on LL define statements.

Removal of hardware-related macros in HAL2

All hardware macros have been removed from the HAL DAC driver, and equivalent services are ensured through the LL APIs.

Revised and optimized HAL state machine

The DAC state machine now is split into:

  1. The DAC state machine

  2. The DAC channel state machine

Revised and optimized HAL API status returns

The HAL DAC functions were updated to return:

  • HAL_INVALID_PARAM: in case of a NULL p_config structure pointer.

  • HAL_ERROR: in case of an error.

  • HAL_TIMEOUT: in case of a user timeout.

  • HAL_BUSY: in case of an ongoing process.

  • HAL_OK: in case of a successfully completed operation.

Revised and optimized HAL error management

The HAL error handling mechanisms have been redesigned to improve the detection, reporting, and handling of errors. This provides more detailed and consistent error information.

New APIs for filtering optional asynchronous process interrupts

New APIs are provided in the HAL DAC to filter and manage asynchronous process interrupts :

HAL_DAC_StartChannel_DMA_Opt

HAL_DAC_StartDualChannel_DMA_Opt.

Replaced TypeDef suffix with _t in type names

All TypeDef parts of the HAL DAC driver have been removed and replaced by _t.

Replaced nonmodifiable pointers with const keywords

Const keywords have been added to non-modifiable pointers to ensure that either the pointer itself or the data it points to cannot be modified. This enhances code safety and readability, prevents unintended modifications, and renders code more robust and maintainable.

Assertion implementation and usage in HAL1

The parameters and state are checked using ASSERT_DBG_STATE and ASSERT_DBG_PARAM macro.

Merge HAL extension files with common ones and remove the EX prefix from APIs.

Only one HAL DAC header file remains and all macros, define statements, and functions from hal_dac_ex.h have been moved to hal_dac.h.

Add HAL PPP Services for Drivers with Handle to Retrieve Corresponding Peripheral Clock Frequency.

HAL DAC provides new API to retrieve clock frequency HAL_DAC_GetClockFreq.

Replace Finite Parameter Defines (Including PPP Instances) with Enum Types at HAL Levels.

Finite parameters (including DAC instances) have been converted into enumerated types (enums) at HAL level. This improves code readability, maintainability, and type safety.

Change Channel Argument to 0-Based Enumeration in Timer Channels

The HAL channels are now represented as an incremental 0-based enumeration.

Optimize HAL PPP IRQ Handlers by Reordering Processes and Error Management Statements to Prioritize Critical Interrupts

In HAL2, the implementation of HAL_DAC_IRQHandler API has been improved to prioritize the handling of critical interrupts.

Add HAL_PPP Prefix to All HAL Peripheral APIs (Defines, Macros, Types, and Functions).

All HAL DAC functions start with HAL_DAC. All HAL DAC enum and struct start with hal_dac.

Other HAL DAC changes

Concept

Consideration

Change API to set: DAC_CHIPCONNECT_EXTERNAL or DAC_CHIPCONNECT_INTERNAL or DAC_CHIPCONNECT_BOTH.

HAL1:

#define DAC_CHIPCONNECT_EXTERNAL
#define DAC_CHIPCONNECT_INTERNAL
#define DAC_CHIPCONNECT_BOTH

HAL2:

typedef enum
{
    HAL_DAC_OUTPUT_CONNECTION_EXTERNAL = LL_DAC_OUTPUT_CONNECT_GPIO,
    HAL_DAC_OUTPUT_CONNECTION_INTERNAL = LL_DAC_OUTPUT_CONNECT_INTERNAL
} hal_dac_output_connection_t;

Note

DAC_CHIPCONNECT_BOTH was removed: In HAL2, the equivalent is HAL_DAC_OUTPUT_CONNECTION_INTERNAL, as long as the DAC output buffer mode is configured HAL_DAC_OUTPUT_BUFFER_ENABLED.